package com.adinnet.api.childStudyToday.controller;


import com.adinnet.api.child.service.ChildService;
import com.adinnet.api.childStudyToday.model.VO.ChildStudyTodayResp;
import com.adinnet.api.childStudyToday.model.VO.ChildStudyWeekResp;
import com.adinnet.api.childStudyToday.service.ChildStudyTodayService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 今日学习时间 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/api/childStudyToday")
public class ChildStudyTodayController {


    @Autowired
    private ChildService childService;

    @Autowired
    private ChildStudyTodayService childStudyTodayService;

    /**
     * 查询今日学习情况
     *
     * @return
     */
    @GetMapping("getChildStudyToday")
    public JsonResult getChildStudyToday(@RequestParam(value = "childId")Integer childId) {
        try{
            if (childId==null) {
                return JsonResult.error("儿童Id不能为空");
            }
            ChildStudyTodayResp resp=childStudyTodayService.getChildStudyToday(childId);
            return JsonResult.ok().put("data",resp);
        }catch (Exception e){
            return JsonResult.error("查询失败！");
        }
    }


    /**
     * 查询本周视频学习情况
     *
     * @return
     */
    @GetMapping("getThisWeekVideoTime")
    public JsonResult getThisWeekVideoTime(@RequestParam(value = "childId")Integer childId) {
        try {
            if (childId==null) {
                return JsonResult.error("儿童Id不能为空");
            }
            ChildStudyWeekResp resp=childStudyTodayService.getThisWeekVideoTime(childId);
            return JsonResult.ok().put("data",resp);
        } catch (BizException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            return JsonResult.error("操作失败！");
        }
    }

}
